import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = "/system-service/resourceModule/listResourceModule",
  save = "/system-service/resourceModule/saveResourceModule",
  edit = "/system-service/resourceModule/updateResourceModule",
  get = "/system-service/resourceModule/getResourceModule",
  deleteBatch = "/system-service/resourceModule/batchDeleteResourceModule",
}

export const listModule = (params) => {
  return defHttp.get({ url: Api.list, params });
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateModule = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
}

/**
 * 查询详情
 * @param params
 */
export const getModuleById = (params) => {
  return defHttp.get({ url: Api.get, params });
}

/**
 * 删除
 * @param params
 */
export const deleteModule = (params, handleSuccess) => {
  return defHttp.delete({
    url: Api.deleteBatch, data: {
      ids: [params.id]
    }
  }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDeleteModule = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
